<?php

class Model_Device extends ORM {
    protected  $_table_name = 'device';

    protected $_belongs_to = array(
    	'Category' => array(
            'model'       => 'category',
            'foreign_key' => 'category_id',
    ),
    );

    public function rules()
    {
        return array(
            'name' => array(
                array('not_empty')
            ),
            'description' => array(
                array('not_empty')
            ),
            'image' => array(
                array('not_empty')
            ),
            'category_id' => array(
                array('in_array', array(':value', ORM::factory('category')->find_all()->as_array('id', 'id')))
            )
        );
    }
}